package com.fdmgroup.benchmarker.lib.thread;



public class TaskThread implements Runnable {
	private String mThreadId;
	private BenchmarkTask mTask;
	private int mTasksPerformed = 0;
	private Flag mIsRunning;
	private volatile Counter mThreadCounter;
	private Object mO;

	public TaskThread(String threadId, BenchmarkTask task, Counter threadCounter,Flag isRunning,Object o) {
		mThreadId = threadId;
		mTask = task;
		mThreadCounter = threadCounter;
		mO = o;
		mIsRunning = isRunning;
	}

	public void run() {
		synchronized(mO){
			//
		}
		while (mIsRunning.value()) {
			mTask.performTask();
			mTasksPerformed++;
			Thread.yield();
		}
		synchronized (mThreadCounter) {
			mThreadCounter.decrement();
			mThreadCounter.notifyAll();
		}
	}

	public int getNumberOfTasksPerformed() {
		return mTasksPerformed;
	}

	public String getThreadId() {
		return mThreadId;
	}
}
